
from fastapi import APIRouter, Depends
from sqlalchemy.ext.asyncio import AsyncSession
from starlette.requests import Request

from config.get_db import get_db
from module_doc.entity.vo.bg_file_category_vo import BgFileCategoryPageModel
from module_doc.service.bg_file_category_service import BgFileCategoryService
from utils.response_util import ResponseUtil

# 公开的分类接口（不需要认证）
publicCategoryController = APIRouter(prefix='/public/category')




# 公开接口
@publicCategoryController.get('/list')
async def get_public_categories(
        request: Request,
        query_db: AsyncSession = Depends(get_db)
):
    """
    获取公开的分类列表（不需要认证）
    """
        # 获取所有分类
    query_object = BgFileCategoryPageModel()
    categories = await BgFileCategoryService.get_bg_file_category_list(query_db, query_object, "", is_page=False)
    return ResponseUtil.success(data=categories)

@publicCategoryController.get('/tree')
async def get_public_category_tree(
        request: Request,
        query_db: AsyncSession = Depends(get_db)
):
    """
    获取公开的分类树（不需要认证）
    """
    tree_data = await BgFileCategoryService.get_bg_file_category_tree(query_db, None)
    return ResponseUtil.success(data=tree_data)

@publicCategoryController.get('/children/{parentId}')
async def get_public_category_children(
        request: Request,
        parentId: int,
        query_db: AsyncSession = Depends(get_db)
):
    """
    获取公开的子分类列表（不需要认证）
    """
    children_data = await BgFileCategoryService.get_bg_file_category_children(query_db, parentId)
    return ResponseUtil.success(data=children_data)